package com.atstudy.headline.web.admin.controller.comment;

import com.atstudy.headline.entity.Comments;
import com.atstudy.headline.result.Result;
import com.atstudy.headline.web.admin.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/comment")
public class CommentController {

    @Autowired
    private CommentsService commentsService;

    // 获取评论列表
    @GetMapping
    public Result<List<Comments>> list() {
        List<Comments> comments = commentsService.list();
        return Result.ok(comments);
    }

    // 删除评论
    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Integer id) {
        commentsService.removeById(id);
        return Result.ok();
    }

    // 更新评论状态
    @PutMapping("/{id}/status")
    public Result<Void> updateStatus(@PathVariable Integer id, @RequestParam Integer status) {
        Comments comment = new Comments();
        comment.setCommentId(id);
        comment.setStatus(status);
        commentsService.updateById(comment);
        return Result.ok();
    }
}